1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.escape;
18
19 import com.google.common.annotations.GwtCompatible;
20 import com.google.common.collect.ImmutableMap;
21
22 import junit.framework.TestCase;
23
24 import java.util.Map;
25
26
27
28
29 @GwtCompatible
30 public class ArrayBasedEscaperMapTest extends TestCase {
31 public void testNullMap() {
32 try {
33 ArrayBasedEscaperMap.create(null);
34 fail("expected exception did not occur");
35 } catch (NullPointerException e) {
36
37 }
38 }
39
40 public void testEmptyMap() {
41 Map<Character, String> map = ImmutableMap.of();
42 ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);
43
44 assertEquals(0, fem.getReplacementArray().length);
45 }
46
47 public void testMapLength() {
48 Map<Character, String> map = ImmutableMap.of(
49 'a', "first",
50 'z', "last");
51 ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);
52
53 assertEquals('z' + 1, fem.getReplacementArray().length);
54 }
55
56 public void testMapping() {
57 Map<Character, String> map = ImmutableMap.of(
58 '\0', "zero",
59 'a', "first",
60 'b', "second",
61 'z', "last",
62 '\uFFFF', "biggest");
63 ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);
64 char[][] replacementArray = fem.getReplacementArray();
65
66 assertEquals(65536, replacementArray.length);
67
68 assertNotNull(replacementArray[replacementArray.length - 1]);
69
70 for (int n = 0; n < replacementArray.length; ++n) {
71 char c = (char) n;
72 if (replacementArray[n] != null) {
73 assertEquals(map.get(c), new String(replacementArray[n]));
74 } else {
75 assertFalse(map.containsKey(c));
76 }
77 }
78 }
79 }